package com.nit.test;

import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;

public class MarkdownToHtmlConverter {
    public static void main(String[] args) {


        String inputFilePath = "F:\\仓库\\gitee\\nit-doc\\java\\springboot笔记.md";
        String outputFilePath ="F:\\仓库\\gitee\\nit-doc\\java\\springboot笔记11111.html";

        try {
            // 读取Markdown文件
            String markdownContent = new String(Files.readAllBytes(Paths.get(inputFilePath)));

            // 解析Markdown内容
            Parser parser = Parser.builder().build();
            
            Node document = parser.parse(markdownContent);

            // 渲染为HTML
            HtmlRenderer renderer = HtmlRenderer.builder().build();
            String htmlContent = renderer.render(document);

            // 写入HTML文件
            try (BufferedWriter writer = new BufferedWriter(new FileWriter(outputFilePath))) {
                writer.write(htmlContent);
            }

            System.out.println("Conversion successful! HTML file saved to: " + outputFilePath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}